#include "tracker_manager.h"
#include "tracker.h"

using namespace bevdet::tracker;

#include <iostream>

ObjectSptrVector TrackerManager::getFusedObjects(void)
{
    ObjectSptrVector objectSptrVector;

    for (auto& i : trackersUMap_) {
        if (i.second->getStatus() == -1) {
            continue;
        }

        objectSptrVector.emplace_back(i.second->get());
    }

    return objectSptrVector;
}

void TrackerManager::fuse(int64_t microTs, const MultiAssociatedObject& multiAssociatedObject)
{
    for (auto& i : multiAssociatedObject) {
        std::shared_ptr<Tracker> trackerSptr { nullptr };

        if (i.first == nullptr) {
            trackerSptr = std::make_shared<Tracker>(id_++);
            trackersUMap_.emplace(trackerSptr->getId(), trackerSptr);
            std::cout << "create" << std::endl;
        } else {
            trackerSptr = trackersUMap_[i.first.get()->id];
            std::cout << "old" << std::endl;
        }

        trackerSptr->fuse(microTs, i.second);
        std::cout << "fuse" << std::endl;
    }
}
